/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-06-04 16:08:31
 * @LastEditTime : 2023-07-13 15:13:54
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\module\RouterList.jsx
 * @Description  :
 */
import { useSize } from 'ahooks'
import { DescriptionsModal } from './DescriptionsModal'
import { TableList } from './TableList'
import { SelectModal } from './SelectModal'
import { EditTableModal } from './EditTableModal'
import { TreeSelectModule } from './TreeSelectModule'
import { useRef } from 'react'

// 二级页弹出层
export const TwoRouter = ({ data }) => {
    const ModalBox = useRef()
    const size = useSize(ModalBox)
    return (
        <div className="TwoRouterModal">
            {data.other.header && <DescriptionsModal data={data.other.oneData} pageHeaderData={data.other.header} />}
            <div className={data.modal === 'TreeSelectModule' ? 'TreeSelectModule' : 'templateBox'} ref={ModalBox}>
                {(() => {
                    const { modal, other } = data
                    const { header, ...TableListData } = other
                    if (size) {
                        const { height } = size
                        const TemplateList = {
                            TableList,
                            EditTableModal,
                            TreeSelectModule,
                        }
                        console.log('打开二级页 --', TableListData.page)
                        const Template = TemplateList[modal]
                        return <Template height={height} TableListData={TableListData} router="TwoRouter" />
                    } else {
                        return <div>加载中</div>
                    }
                })()}
            </div>
        </div>
    )
}

// 三级页
export const ThrRouter = ({ data }) => {
    const ModalBox = useRef()
    const size = useSize(ModalBox)
    return (
        <div className="ThrRouterModal">
            <div className="templateBox" ref={ModalBox}>
                {(() => {
                    const { modal, other } = data
                    const { header, ...TableListData } = other
                    if (size) {
                        const { height } = size
                        const TemplateList = {
                            TableList,
                            SelectModal,
                        }
                        console.log('打开三级页 --', TableListData.page)
                        const Template = TemplateList[modal]
                        return <Template height={height} TableListData={TableListData} router="ThrRouter" />
                    } else {
                        return <div>加载中</div>
                    }
                })()}
            </div>
        </div>
    )
}
